﻿Imports Actuariat.comptes
Imports OMANE.moteurTauxGaranti2

Public Class vueCompteDeResultat_V2
    Inherits vueCompte_V2

#Region "Initialisation"
    Protected Overrides Sub initNbLignes()
        For i As Integer = 1 To 46
            Me.Rows.Add()
            Me.Rows(i - 1).Height = 15
        Next
        'Cas particuliers
        Rows(3).Height = 6
        Rows(18).Height = 6
        Rows(34).Height = 6
    End Sub
    Protected Overrides Sub initTitresBlocs()
        initLignesBlocCompteTechVie()
        initLignesBlocCompteTechNonVie()
        initLignesBlocCompteNonTech()
    End Sub
    Protected Overrides Sub initLignesTitresGeneraux()
        Me.Rows(0).Cells(0).Value = "COMPTE DE RESULTAT"
    End Sub
    Private Sub initLignesBlocCompteTechVie()
        'Titre du compte technique vie
        Me.Rows(2).Cells(0).Value = "COMPTE TECHNIQUE VIE"
        Me.Rows(2).Cells(0).Style = styleCellulesTitre2()
        'Titre du compte de résultat
        Me.Rows(4).Cells(0).Value = "Produits"
        Me.Rows(5).Cells(0).Value = "   Primes DC"
        Me.Rows(6).Cells(0).Value = "   Provision DC ouverture"
        Me.Rows(7).Cells(0).Value = "   Produit des placements"
        Me.Rows(8).Cells(0).Value = "Charges"
        Me.Rows(9).Cells(0).Value = "   Charge des sinistres"
        Me.Rows(10).Cells(0).Value = "   Provision DC clôture"
        Me.Rows(11).Cells(0).Value = "   Frais de gestion"
        Me.Rows(12).Cells(0).Value = "   Charge des placements"
        Me.Rows(13).Cells(0).Value = "   Produit des placements transférés"
        Me.Rows(14).Cells(0).Value = "   Commission apporteur"
        Me.Rows(15).Cells(0).Value = "Résultat technique vie"
        Me.Rows(15).Cells(0).Style = styleCellulesAccentuees()

        Me.Rows(4).Cells(0).Style.Font = New System.Drawing.Font("Tahoma", 9, FontStyle.Underline)
        Me.Rows(8).Cells(0).Style.Font = New System.Drawing.Font("Tahoma", 9, FontStyle.Underline)
    End Sub
    Private Sub initLignesBlocCompteTechNonVie()

        'Titre du compte de résultat
        Me.Rows(17).Cells(0).Value = "COMPTE TECHNIQUE NON VIE"
        Me.Rows(17).Cells(0).Style = styleCellulesTitre2()

        'Titre du compte de résultat
        Me.Rows(19).Cells(0).Value = "Produits"
        Me.Rows(20).Cells(0).Value = "   Primes IT TTC"
        Me.Rows(21).Cells(0).Value = "   Provision de rente ouverture"
        Me.Rows(22).Cells(0).Value = "   PPRC ouverture"
        Me.Rows(23).Cells(0).Value = "   Produit des placements alloués"
        Me.Rows(24).Cells(0).Value = "Charges"
        Me.Rows(25).Cells(0).Value = "   Taxe d'assurance"
        Me.Rows(26).Cells(0).Value = "   Sinistres réglés"
        Me.Rows(27).Cells(0).Value = "   Provision de rente clôture"
        Me.Rows(28).Cells(0).Value = "   PPRC clôture"
        Me.Rows(29).Cells(0).Value = "   Frais Natixis"
        Me.Rows(30).Cells(0).Value = "   Commission apporteur"
        Me.Rows(31).Cells(0).Value = "Résultat technique non vie"
        Me.Rows(31).Cells(0).Style = styleCellulesAccentuees()

        Me.Rows(19).Cells(0).Style.Font = New System.Drawing.Font("Tahoma", 9, FontStyle.Underline)
        Me.Rows(24).Cells(0).Style.Font = New System.Drawing.Font("Tahoma", 9, FontStyle.Underline)
    End Sub
    Private Sub initLignesBlocCompteNonTech()
        'Titre du compte de résultat
        Me.Rows(33).Cells(0).Value = "COMPTE NON TECHNIQUE"
        Me.Rows(33).Cells(0).Style = styleCellulesTitre2()
        'Titre du compte de résultat
        Me.Rows(35).Cells(0).Value = "Produits"
        Me.Rows(36).Cells(0).Value = "   Résultat vie"
        Me.Rows(37).Cells(0).Value = "   Résultat non vie"
        Me.Rows(38).Cells(0).Value = "   Produit des placements alloués"
        Me.Rows(39).Cells(0).Value = "   Produit des placements (non vie)"
        Me.Rows(40).Cells(0).Value = "   Produit des placements transférés"

        Me.Rows(41).Cells(0).Value = "Charges"
        Me.Rows(42).Cells(0).Value = "   Charge des placements (non vie)"
        Me.Rows(43).Cells(0).Value = "   Impôts sur les bénéfices et taxes"
        Me.Rows(44).Cells(0).Value = "Résultat"
        Me.Rows(44).Cells(0).Style = styleCellulesAccentuees()

        Me.Rows(35).Cells(0).Style.Font = New System.Drawing.Font("Tahoma", 9, FontStyle.Underline)
        Me.Rows(41).Cells(0).Style.Font = New System.Drawing.Font("Tahoma", 9, FontStyle.Underline)
    End Sub
#End Region

    Public Overrides WriteOnly Property moteurTxGaranti2() As moteurTauxGaranti2.Moteur_Methode2
        Set(ByVal value As moteurTauxGaranti2.Moteur_Methode2)
            MyBase.moteurTxGaranti2 = value
            AddHandler _resultatsScenarioCentral.compteCRTvie_hasChanged, AddressOf onResultatsScenCent_CompteTechVie_HasChanged
            AddHandler _resultatsScenarioCentral.compteCRTNonVie_hasChanged, AddressOf onResultatsScenCent_CompteTechNonVie_HasChanged
            AddHandler _resultatsScenarioCentral.compteCRTNonTechnique_hasChanged, AddressOf onResultatsScenCent_CompteNonTech_HasChanged
        End Set
    End Property

#Region "Méthodes de dessin"
    Protected Overrides Sub paintBlocs(ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs)
        'CompteTechnique Vie
        paintBloc(e, 2, 15)
        'Compte technique non vie
        paintBloc(e, 17, 31)
        'Compte non technique
        paintBloc(e, 33, 44)
    End Sub
    Protected Overrides Function cellFormat(ByVal rowIndex As String, ByVal columnIndex As String) As String
        If rowIndex <> 0 And columnIndex <> 0 Then Return _formatDefaut Else Return ""
    End Function
    Protected Overrides Function cellBackColor(ByVal rowIndex As String, _
                                   ByVal columnIndex As String, _
                                   ByVal ligneHautBloc As Integer, _
                                   ByVal ligneBasBloc As Integer) As System.Drawing.Color
        If rowIndex = ligneHautBloc Then
            Return Color.FromArgb(231, 213, 231)
        ElseIf rowIndex = ligneBasBloc Then
            Return Color.FromArgb(255, 230, 30)
        Else
            Return Color.White
        End If
    End Function
    Protected Overrides Function cellAlignment(ByVal rowIndex As Integer, ByVal columnIndex As Integer) As StringAlignment
        If columnIndex = 0 Then Return StringAlignment.Near Else Return StringAlignment.Far
    End Function
    Protected Overrides Function cellFont(ByVal rowIndex As Integer, ByVal columnIndex As Integer, ByVal ligneHautBloc As Integer, ByVal ligneBasBloc As Integer) As Font
        If rowIndex = ligneHautBloc Or rowIndex = ligneBasBloc Then
            Return New System.Drawing.Font("Tahoma", 9, FontStyle.Bold)
        Else
            Return New System.Drawing.Font("Tahoma", 9, FontStyle.Regular)
        End If
    End Function
#End Region

#Region "Rafraichissement des chiffres des comptes"
    Private Sub onResultatsScenCent_CompteTechVie_HasChanged(ByVal sender As Object, ByVal e As EventArgs)
        refreshValeursBlocCompteTechniqueVie()
    End Sub
    Private Sub onResultatsScenCent_CompteNonTech_HasChanged(ByVal sender As Object, ByVal e As EventArgs)
        refreshValeursBlocCompteNonTechnique()
    End Sub
    Private Sub onResultatsScenCent_CompteTechNonVie_HasChanged(ByVal sender As Object, ByVal e As EventArgs)
        refreshValeursBlocCompteTechniqueNonVie()
    End Sub
    Protected Overrides Sub refreshValeursBlocs()
        refreshValeursBlocCompteTechniqueVie()
        refreshValeursBlocCompteTechniqueNonVie()
        refreshValeursBlocCompteNonTechnique()
    End Sub
    Private Sub refreshValeursBlocCompteTechniqueVie()
        If Not _resultatsScenarioCentral Is Nothing Then
            Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None

            For i As Integer = 1 To _nbAnneesProjection
                With _resultatsScenarioCentral.compteCRTVie
                    'Les valeurs
                    If Not .primesDC Is Nothing Then
                        If i <= .primesDC.Count Then
                            Rows(5).Cells(i).Value = .primesDC(i - 1) / unite
                            Rows(6).Cells(i).Value = .PmDCouv(i - 1) / unite
                            Rows(7).Cells(i).Value = .produitPlacements(i - 1) / unite
                            Rows(9).Cells(i).Value = -.sinRegles(i - 1) / unite
                            Rows(10).Cells(i).Value = -.PmDCclot(i - 1) / unite
                            Rows(11).Cells(i).Value = -.FG(i - 1) / unite
                            Rows(12).Cells(i).Value = -.chargePlacements(i - 1) / unite
                            Rows(13).Cells(i).Value = -.produitPlacementsTransferes(i - 1) / unite
                            Rows(14).Cells(i).Value = -.comApporteur(i - 1) / unite
                            Rows(15).Cells(i).Value = .resultatVie(i - 1) / unite
                        End If
                    End If
                End With
            Next
            Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells

        End If

    End Sub
    Private Sub refreshValeursBlocCompteTechniqueNonVie()
        If Not _resultatsScenarioCentral Is Nothing Then
            Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
            For i As Integer = 1 To _nbAnneesProjection
                'Les valeurs
                With _resultatsScenarioCentral.compteCRTNonVie
                    If Not .primesIT Is Nothing Then
                        If i <= .primesIT.Count Then
                            Me.Rows(20).Cells(i).Value = .primesIT(i - 1) / unite
                            Me.Rows(21).Cells(i).Value = .pmRenteouv(i - 1) / unite
                            Me.Rows(22).Cells(i).Value = .pmPPRCouv(i - 1) / unite
                            Me.Rows(23).Cells(i).Value = .produitPlacementsAlloues(i - 1) / unite
                            Me.Rows(25).Cells(i).Value = -.taxeAssu(i - 1) / unite
                            Me.Rows(26).Cells(i).Value = -.sinReglesIT(i - 1) / unite
                            Me.Rows(27).Cells(i).Value = -.pmRenteClot(i - 1) / unite
                            Me.Rows(28).Cells(i).Value = -.pmPPRCClot(i - 1) / unite
                            Me.Rows(29).Cells(i).Value = -.FG(i - 1) / unite
                            Me.Rows(30).Cells(i).Value = -.comApporteur(i - 1) / unite
                            Me.Rows(31).Cells(i).Value = .resultatsNonVie(i - 1) / unite
                        End If
                    End If
                End With
            Next
            Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
        End If
    End Sub
    Private Sub refreshValeursBlocCompteNonTechnique()
        If Not _resultatsScenarioCentral Is Nothing Then
            Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
            For i As Integer = 1 To _nbAnneesProjection
                'Les valeurs
                With _resultatsScenarioCentral.compteCRNonTechnique
                    If Not .resultatVie Is Nothing Then
                        If i <= .resultatVie.Count Then
                            Me.Rows(36).Cells(i).Value = .resultatVie(i - 1) / unite
                            Me.Rows(37).Cells(i).Value = .resultatNonVie(i - 1) / unite
                            Me.Rows(38).Cells(i).Value = .produitPlacementsAlloues(i - 1) / unite
                            Me.Rows(39).Cells(i).Value = .produitPlacements(i - 1) / unite
                            Me.Rows(40).Cells(i).Value = -.produitPlacementsTransferes(i - 1) / unite
                            Me.Rows(42).Cells(i).Value = -.chargePlacements(i - 1) / unite
                            Me.Rows(43).Cells(i).Value = -.impotsEtTaxes(i - 1) / unite
                            Me.Rows(44).Cells(i).Value = .resultat(i - 1) / unite
                        End If
                    End If
                End With
            Next
            Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
        End If
    End Sub
#End Region

#Region "Rafraichissement du dessin des comptes"
    Private Sub refreshOssature()
        refreshNbColonnesProjection()
        refreshTitreGeneral()
    End Sub
    Private Sub refreshNbColonnesProjection()
        ColumnCount = _nbAnneesProjection + 1
        For Each c As DataGridViewColumn In Columns
            c.DefaultCellStyle.Format = "#,##0"
        Next
    End Sub
    Private Sub refreshTitreGeneral()
        'Années de projection
        For j As Integer = 1 To _nbAnneesProjection
            Me.Rows(0).Cells(j).Value = CStr(j) - 1 + _anneeDepart
        Next
    End Sub
    Protected Overrides Sub refreshTitresGeneraux()
        'Années de projection
        For j As Integer = 1 To _nbAnneesProjection
            Me.Rows(0).Cells(j).Value = CStr(j - 1 + _anneeDepart)
        Next
    End Sub
#End Region

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        RemoveHandler _resultatsScenarioCentral.compteCRTvie_hasChanged, AddressOf onResultatsScenCent_CompteTechVie_HasChanged
        RemoveHandler _resultatsScenarioCentral.compteCRTNonVie_hasChanged, AddressOf onResultatsScenCent_CompteTechNonVie_HasChanged
        RemoveHandler _resultatsScenarioCentral.compteCRTNonTechnique_hasChanged, AddressOf onResultatsScenCent_CompteNonTech_HasChanged
        MyBase.Dispose(disposing)
    End Sub

End Class